package benny_driving_ser.action;

import java.io.IOException;
import java.io.PrintWriter;

import benny_driving_ser.dao.DriPayRentDao;
import benny_driving_ser.dao.impl.DriPayRentDaoImpl;
import benny_driving_ser.entity.SessionAttributeDriId;
import benny_driving_ser.util.SessionUtil;

public class DriPayRentAction extends BaseAction {

	private DriPayRentDao dao;
	private int driId;
	private PrintWriter out;
	private int outInt = 0;

	public String driPayRent() {
		SessionAttributeDriId sad = SessionUtil.getInstance()
				.verifySessionIdForDri(request);

		try {
			out = response.getWriter();
			if (sad != null) {
				driId = Integer.parseInt(sad.getValue());

				System.out.println("sad:" + sad + "attribute:" + sad.getValue());
				response.setContentType("text/html");
				response.setCharacterEncoding("utf-8");
				dao = new DriPayRentDaoImpl();

				outInt = dao.driPayRent(driId);
				out.println(outInt);
				out.flush();
				out.close();

			}
			out.println(-1);
			out.flush();
			out.close();

		} catch (IOException e) {
			e.printStackTrace();
		} catch (NumberFormatException e) {
			e.printStackTrace();
			outInt = 5;
			out.println(outInt);
			out.flush();
			out.close();
			return "fail";
		}

		return "success";
	}

	public DriPayRentDao getDao() {
		return dao;
	}

	public void setDao(DriPayRentDao dao) {
		this.dao = dao;
	}

	public PrintWriter getOut() {
		return out;
	}

	public void setOut(PrintWriter out) {
		this.out = out;
	}

	public int getOutInt() {
		return outInt;
	}

	public void setOutInt(int outInt) {
		this.outInt = outInt;
	}

	public int getDriId() {
		return driId;
	}

	public void setDriId(int driId) {
		this.driId = driId;
	}

}
